package com.example.dmservice.excelInput.service;

import com.alibaba.excel.EasyExcel;
import com.example.dmdomain.entity.ProvinceCity;
import com.example.dmservice.exceloutput.service.ExcelOutPutServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.InputStream;

/**
 * @author yym
 */
@Service
public class ExcelInPutServiceImpl {

	private static final Logger logger = LoggerFactory.getLogger(ExcelOutPutServiceImpl.class);

	public void readTimeDataExcel(InputStream inputStream, String type) {
		switch (type) {
			case "time":
				logger.info("开始读取分时时段数据");
				EasyExcel.read(inputStream, new TimeSlotDataListener()).sheet("分时时段").doRead();
				break;
			case "price":
				logger.info("开始读取电价数据");
				EasyExcel.read(inputStream, new ElectricityPriceDataListener()).sheet("电价表").doRead();
				break;
			case "city":
				logger.info("开始导入城市数据");
				EasyExcel.read(inputStream, ProvinceCity.class,new CityListener()).sheet("全国城市表").doRead();
				break;
			default:
				throw new RuntimeException("类型错误无法导入");
		}

	}


}
